home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
varia
/
interp18.lha
/
interp-1.8
/
Context.cc
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-20
|
3KB
|
91 lines
// Context.cc -- the definition of the member functions for class Context.
// Copyright (C) 1989 Carey Richard Murphey.
// (rich@rice.edu) 5310 Rutherglenn, Houston, TX 77096
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 1, or (at your option)
// any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "Context.h"
#if !defined(__OPTIMIZE__) || defined(INLINE)
#ifndef INLINE
#define INLINE
#endif
INLINE void Context:: open () // create a new symbol table at the
// opening of a block.
{
tab.add_high (new StringSymbolpAVLMap (new Double_Pointer(0.)));
}
INLINE void Context:: close () // close a context
{
if (tab.high_element ()->length () == 0)
delete tab.high_element ();
tab.del_high ();
};
INLINE int Context:: contains (String& name)
{
// Look through the symbol tables for a given name.
// Return 1 if found or 0 if not found.
for (int i = tab.high(); i > tab.ecnef(); tab.prev(i))
{
if (tab[i]->contains(name))
return 1;
}
return 0;
}
INLINE int Context:: top_level (String& name)
{
// Look through the top level (outermost) symbol tables for a given name.
// Return 1 if found or 0 if not found.
if (tab.high_element ()->contains(name))
return 1;
return 0;
}
INLINE Symbol& Context:: operator [] (String& name)
{
// Look through the symbol tables for a given name.
// If not found, put it in the outermost table.
// Return a reference to that symbol.
for (int i = tab.high(); i > tab.ecnef(); tab.prev(i))
{
if (tab[i]->contains(name))
return *(*tab[i])[name];
}
return *(*tab.high_element ())[name];
}
INLINE Table Context:: table (String& name)
{
// Look through the symbol tables for a given name.
// If not found, return a pointer to the outermost table without installing.
// Return a pointer to table .
for (int i = tab.high(); i > tab.ecnef(); tab.prev(i))
{
if (tab[i]->contains(name))
return tab[i];
}
return tab.high_element ();
}
#endif